package com.visionet.waveletData.web.service.account;

import com.visionet.waveletData.web.common.utils.PageInfo;
import com.visionet.waveletData.web.entity.account.User;
import com.visionet.waveletData.web.repository.account.UserDao;
import com.visionet.waveletData.web.repository.account.UserDaoPlus;
import com.visionet.waveletData.web.repository.business.specs.UserInfoSearchSpecs;
import com.visionet.waveletData.web.service.BaseService;
import com.visionet.waveletData.web.service.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 用户管理业务类.
 * 
 * @author xt
 */
@Service
public class AccountService extends BaseService{
//	public static final String HASH_ALGORITHM = "SHA-1";
//    public static final String HASH_ALGORITHM_MD5 = "MD5";
//	private static final int SALT_SIZE = 8;
//
//	private static Logger logger = LoggerFactory.getLogger(AccountService.class);
//	
	@Resource 
	private UserDaoPlus userDaoPlus;
	@Autowired
	private UserDao userDao;
	
	
	/**
	 * 根据条件查询用户信息
	 * @param userInfo
	 * @return
	 */
	public Page<User> findUserInfoByConditionForList(User userInfo,PageInfo pageInfo){ 
		PageRequest pageRequest = null;
		if(pageInfo==null){
			pageInfo = new PageInfo();
			pageInfo.setPageSize(5000);
		}
		pageRequest=this.getPageRequestInfo(pageInfo);
		Page<User> page = userDao.findAll(UserInfoSearchSpecs.searchTeamByCondition(userInfo),pageRequest);
		pageInfo.setTotalCount(page.getNumberOfElements());
		return page;
		
	}
	
	public PageRequest getPageRequestInfo(PageInfo pageInfo) {
		Sort sort = new Sort(Direction.ASC, "id");
		return new PageRequest(pageInfo.getPageNumber() - 1,pageInfo.getPageSize(), sort);

	}
	
	public User findUserInfoByUserId(Long userId){
      return userDao.findOne(userId);
	}
	
	/**
	 * 更新用户信息
	 * @param userInfo
	 */
	@Transactional(readOnly = false)
	public void saveUser(User userInfo){
		// 如果ID为空则为新增
		if(userInfo.getId() == null){
			userInfo.setUser_type("NORMAL");
			userInfo.setIs_deleted("0");
		}
		userDao.save(userInfo);
	}
	
	/**
	 * 删除用户信息
	 * @param userInfo
	 */
	@Transactional(readOnly = false)
	public void deleteUserInfo(User userInfo){
		if(userInfo.getId() == null){
			throw new ServiceException("id is null!");
		}
		userInfo.setIs_deleted("1");
		userDao.save(userInfo);
		
	}
	
//	/**
//	 * 在保存用户时,发送用户修改通知消息, 由消息接收者异步进行较为耗时的通知邮件发送.
//	 * 
//	 * 如果企图修改超级用户,取出当前操作员用户,打印其信息然后抛出异常.
//	 * 
//	 */
//	@Transactional(readOnly = false)
//	public void saveUser(User user) {
////
////        if(user.getId()==null){
////            throwException(BusinessStatus.REQUIRE,"id is null!");
////        }
////
////        this.checkUserInfo(user);
////
////		// 设定安全的密码，生成随机的salt并经过1024次 sha-1 hash
////		if (StringUtils.isNotBlank(user.getPlainPassword())) {
////			entryptPassword(user);
////		}
////
////		if(!user.getIsLock().equals(user.getUserInfo().getIsLock())){
////			user.getUserInfo().setIsLock(user.getIsLock());
////		}
////		if(user.getRoleList()==null || user.getRoleList().isEmpty()){
////			throw new RestException("role can not be null!");
////		}
////		
////		if(user.getId()>10 && !user.getLoginName().equals(user.getUserInfo().getLoginName())){
////			user.getUserInfo().setLoginName(user.getLoginName());
////		}
////		if(user.getAliasName()!=null && !user.getAliasName().equals(user.getUserInfo().getUserName())){
////			user.getUserInfo().setUserName(user.getAliasName());
////		}
////        if(user.getId()==null){
////            if(this.findByLoginNameAndOrgId(user.getLoginName(),user.getOrgId())!=null){
////                throw new RestException(MessageSourceHelper.GetMessages("register.loginName.exist")+": "+user.getLoginName());
////            }
////            if(!Collections3.isEmpty(this.findByAliasNameAndOrgId(user.getAliasName(),user.getOrgId()))){
////                throw new RestException(MessageSourceHelper.GetMessages("register.aliasName.exist")+": "+user.getAliasName());
////            }
////        }else{
////            User po = userDao.findOne(user.getId());
////            if(!po.getLoginName().equals(user.getLoginName())){
////                if(this.findByLoginNameAndOrgId(user.getLoginName(),user.getOrgId())!=null){
////                    throw new RestException(MessageSourceHelper.GetMessages("register.loginName.exist")+"  "+user.getLoginName());
////                }
////            }
////            if(po.getAliasName()!=null) {
////                if (!po.getAliasName().equals(user.getAliasName())) {
////                    if (!Collections3.isEmpty(this.findByAliasNameAndOrgId(user.getAliasName(), user.getOrgId()))) {
////                        throw new RestException(MessageSourceHelper.GetMessages("register.aliasName.exist") + "  " + user.getAliasName());
////                    }
////                }
////            }else{
////                po.setAliasName(po.getUserInfo().getUserName());
////            }
////        }
////
////        if(user.getUserInfo().getBadge()!=null && user.getUserInfo().getBadge().intValue() == KeyWord.BADGE_TYPE_MODERATOR
////                && user.getUserInfo().getIntegralBadge() == null){
////            user.getUserInfo().setIntegralBadge(IntegralTotalService.IntegralMonthly);
////        }
////        if(user.getUserInfo().getLevel()==null){
////            user.getUserInfo().setLevel(KeyWord.USER_LEVEL_COMMON);
////        }
////        if(user.getUserInfo().getBadge()==null){
////            user.getUserInfo().setBadge(KeyWord.BADGE_TYPE_USER);
////        }
////        if(user.getUserInfo().getIntegral() == null){
////            user.getUserInfo().setIntegral(0F);
////        }
////
////
////        userDao.save(user);
////
////        BaseController.setLocale(user.getUserInfo().getLocale());
////		
////		CacheService.put(CacheService.USER_KEY+user.getId(), user.getUserInfo());
////		
////		if(user.getSecId()!=null){
////			User assistant = userDao.findOne(user.getSecId());
////			if(assistant!=null){
////				//将对应秘书的IsLockSec锁定/解锁
////				if(user.getIsLockSec().intValue()!=assistant.getIsLockSec().intValue()){
////					this.lockSec(user,assistant);
////				}
////				
////				if(user.getId().intValue()!=assistant.getSecId().intValue()){
////					assistant.setSecId(user.getId());
////					userDao.save(assistant);
////				}
////			}
////		}
////		// 发送JMS消息
//////		sendNotifyMessage(user);
////
////		// 运行统计
//////		if (applicationStatistics != null) {
//////			applicationStatistics.incrUpdateUserTimes();
//////		}
////
////		// 业务日志
//////		Map<String,String> map = Maps.newHashMap();
//////		map.put("userId", user.getId().toString());
//////		map.put("loginName", user.getLoginName());
//////		map.put("updateBy", BaseController.getCurrentUserId()==null?"0":BaseController.getCurrentUserId().toString());
//////		BusinessLogger.log("User UPDATE", user.getLoginName(), map);
////		
////		
////		//********************同步node聊天应用****************************
////		Map<String,String> userMap = new HashMap<String,String>();
////		userMap.put("refId", user.getId().toString());
//////		if(StringUtils.isNotBlank(user.getPlainPassword())){
//////			userMap.put("pwd", user.getPlainPassword());
//////		}
////		if(user.getAliasName()!=null && !user.getAliasName().equals(user.getUserInfo().getUserName())){
////			userMap.put("nickName", user.getAliasName());
////		}
////		if(!user.getIsLock().equals(user.getUserInfo().getIsLock())){
////			userMap.put("lockFlag", user.getIsLock().toString());
////		}
////		boolean syncNodeUser = chatConnection.editUser(userMap);
////		if(!syncNodeUser){
////			throw new RestException("sync node data fail");
////		}
//		//********************同步node聊天应用****************************
//	}
//
//
//    private void checkUserInfo(User user){
//        if(userDao.checkByLoginName(user.getUserName(), user.getId()) != null){
//            throw new RestException(MessageSourceHelper.GetMessages("register.loginName.exist"));
//        }
////        if(userDao.checkByAliasName(user.getAliasName(), user.getOrgId(),user.getId()) > 0){
////            throw new RestException(MessageSourceHelper.GetMessages("register.aliasName.exist"));
////        }
//        if (isSupervisor(user.getId())) {
//            logger.warn("Operator{}want to modify admin!", BaseController.getCurrentUserName());
//            throw new ServiceException(MessageSourceHelper.GetMessages("app.service.account.AccountService.modify.admin"));
//        }
//    }
//
//    @Transactional(readOnly = false)
//    public void updateUserRole(Long userId,Set<Role> roleSet) {
//        User po = userDao.findOne(userId);
//        if(po==null){
//            throwException(BusinessStatus.NOTFIND,"id is not exist!");
//        }
////        po.setRoleList(roleSet);
//        userDao.save(po);
//    }
//
//	/**
//	 * 用户修改自己密码
//	 * 领导可以锁定秘书功能
//	 * @param user
//	 */
//	@Transactional(readOnly = false)
//	public void updateUserPasswd(User user) {
//		User po = userDao.findOne(user.getId());
//		
//		// 设定安全的密码，生成随机的salt并经过1024次 sha-1 hash
//		if (StringUtils.isNotBlank(user.getPassword())) {
//			entryptPassword(user);
//			po.setPassword(user.getPassword());
////			po.setPasswordSalt(user.getPassword());
//		}
//		
//		userDao.save(po);
//
////		//********************同步node聊天应用---修改密码****************************
////		Map<String,String> userMap = new HashMap<String,String>();
////		userMap.put("refId", user.getId().toString());
////		if (StringUtils.isNotBlank(user.getPlainPassword())) {
////			userMap.put("pwd", user.getPlainPassword());
////		}
////		boolean syncNodeUser = chatConnection.editUser(userMap);
////		if(!syncNodeUser){
////			throw new RestException("sync node data fail");
////		}
////		//********************同步node聊天应用---修改密码****************************
//	}
//
//
////	@Transactional(readOnly = false)
////	public void updateUserNamePasswd(UserInfoVo vo) {
////		User user = getUser(vo.getId());
////		if(Validator.isNotNull(vo.getPlainPassword()) || !user.getAliasName().equals(vo.getUserName())){
////			if(Validator.isNotNull(vo.getPlainPassword())){
////				user.setPassword(vo.getPlainPassword());
////				user.setPlainPassword(vo.getPlainPassword());
////				entryptPassword(user);
////				user.setPassword(user.getPassword());
////				user.setPasswordSalt(user.getPasswordSalt());
////			}
////			if(!user.getAliasName().equals(vo.getUserName())){
////				user.setAliasName(vo.getUserName());
////			}
////			userDao.save(user);
////			
////			
////			//********************同步node聊天应用---修改昵称和密码****************************
////			Map<String,String> userMap = new HashMap<String,String>();
////			userMap.put("refId", user.getId().toString());
//////			if(Validator.isNotNull(vo.getPlainPassword())){
//////				userMap.put("pwd", user.getPlainPassword());
//////			}
////			if(!user.getAliasName().equals(vo.getUserName())){
////				userMap.put("nickName",vo.getUserName());
////				
////				boolean syncNodeUser = chatConnection.editUser(userMap);
////				if(!syncNodeUser){
////					throw new RestException("sync node data fail");
////				}
////			}
////			//********************同步node聊天应用---修改昵称和密码****************************
////		}
////	}
//	
//	/**
//	 * 领导更换自己的秘书，同时更换对应秘书的领导
//	 * @param userId 领导id
//	 * @param secId 秘书id
//	 */
////	@Transactional(readOnly = false)
////	public void changeSec(Long userId,Long secId) {
////		User leader = this.getUser(userId);
////		
////		//解除秘书
////		if(secId == -1){
////			if(leader.getSecId()!=null){
////				User assistant = this.getUser(leader.getSecId());
////				assistant.setSecId(null);
////				userDao.save(assistant);
////			}
////			leader.setSecId(null);
////			userDao.save(leader);
////			return;
////		}
////		User assistant = this.getUser(secId);
////		if(assistant.getSecId()!=null){
////			throw new RestException(MessageSourceHelper.GetMessages("app.service.account.AccountService.secretary.bound.leader"));
////		}
////		
////		
////		if(leader.getSecId().intValue() == secId.intValue()){
////			throw new RestException(MessageSourceHelper.GetMessages("app.service.account.AccountService.secretary.be.bound"));
////		}
////		
////		leader.setSecId(secId);
////		userDao.save(leader);
////		
////		assistant.setSecId(leader.getId());
////		userDao.save(assistant);
////	}
//	
//	/**
//	 * 领导更换自己的秘书，同时更换对应秘书的领导
//	 * @param secId
//	 */
////	public void changeSec(Long secId) {
////		this.changeSec(BaseController.getCurrentUserId(), secId);
////	}
//	
//	/**
//	 * 锁定/解锁秘书，同时对应领导的isLock也要锁定/解锁
//	 * @param userId 领导id
//	 * @param isSecLock - 1:lock ; 0:unlock
//	 */
////	@Transactional(readOnly = false)
////	public void lockSec(Long userId,Integer isSecLock) {
////		User leader = this.getUser(userId);
////		if(leader.getIsLockSec().intValue() == isSecLock.intValue()){
////			if(isSecLock == SysConstants.IS_SEC_LOCK){
////				throw new RestException(MessageSourceHelper.GetMessages("app.service.account.AccountService.secretary.lock"));
////			}else{
////				throw new RestException(MessageSourceHelper.GetMessages("app.service.account.AccountService.secretary.unlock"));
////			}
////		}
////
////		leader.setIsLockSec(isSecLock);
////		
////		userDao.save(leader);
////		if(leader.getSecId()!=null){
////			this.lockSec(leader, this.getUser(leader.getSecId()));
////		}
////
////	}
//	
//	/**
//	 * 锁定/解锁秘书，同时对应领导的isLock也要锁定/解锁
//	 * @param isLock - 1:lock ; 0:unlock
//	 */
////	public void lockSelfSec(Integer isLock) {
////		this.lockSec(BaseController.getCurrentUserId(), isLock);
////	}
//	
//	/**
//	 * 锁定/解锁 领导与秘书代理关系
//	 * 如果锁定，则同时去除秘书代理权限，并更新Shiro session
//	 * @param leader
//	 * @param assistant
//	 */
////	@Transactional(readOnly = false)
////	private void lockSec(User leader,User assistant){
////		if(assistant.getIsLockSec().intValue() == leader.getIsLockSec().intValue()) return;
////		
////		assistant.setIsLockSec(leader.getIsLockSec());
////		
////		if(leader.getIsLockSec().intValue() == SysConstants.IS_SEC_LOCK.intValue()){	//锁定
////			//去除秘书代理权限
////			assistant.getRoleList().clear();
////			
////			Role role = new Role(this.getRoleIdByName(SysConstants.ASSISTANT));
////			assistant.getRoleList().add(role);
////		}
////		userDao.save(assistant);
////		ShiroUser suser = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
////		suser.isLockSec = leader.getIsLockSec();
////		
////	}
//
//
//	/**
//	 * 设定安全的密码，生成随机的salt并经过1024次 sha-1 hash
//	 * CAS 接口不支持salt
//	 */
//	protected static void entryptPassword(User user) {
//        if(user.getPassword()!=null ){
//            
//            return;
//        }
//        if(HASH_ALGORITHM.equals(PwdEncryptor.PASSWORDS_ENCRYPTION_ALGORITHM)) {
//            byte[] salt = Digests.generateSalt(SALT_SIZE);
//
//            byte[] hashPassword = Digests.sha1(user.getPassword().getBytes(), salt, PwdEncryptor.HASH_INTERATIONS);
//            user.setPassword(Encodes.encodeHex(hashPassword));
//        }else if(HASH_ALGORITHM_MD5.equals(PwdEncryptor.PASSWORDS_ENCRYPTION_ALGORITHM)) {
//                user.setPassword(Md5Util32.md5(user.getPassword()));
//        }
//	}
//	
//	public static String getEntryptPassword(String plainPassword,String salt){
//		byte[] hashPassword = Digests.sha1(plainPassword.getBytes(), Encodes.decodeHex(salt), PwdEncryptor.HASH_INTERATIONS);
//		return Encodes.encodeHex(hashPassword);
//	}
//
//
//	
//	public Page<User> searchUser(Long orgId,Map<String, Object> searchParams,
//			int pageNumber, int pageSize,String sortType) {
//		PageRequest pageRequest = buildPageRequest(pageNumber, pageSize, sortType);
//		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
//		filters.put("id", new SearchFilter("id", Operator.GT, 1));
//		if(orgId!=null&&orgId.longValue()!=0){
//			filters.put("orgId", new SearchFilter("orgId", Operator.EQ, orgId));
//		}
//        return userDao.findAll(UserSearchSpecs.bySearchFilter(filters.values()),pageRequest);
//	}
//
//
//	/**
//	 * 获取全部用户对象，并在返回前完成LazyLoad属性的初始化。
//	 */
//	public List<User> getAllUserInitialized() {
//		List<User> result = (List<User>) userDao.findAll();
////		for (User user : result) {
////			Hibernates.initLazyProperty(user.getRoleList());
////		}
//		return result;
//	}
//
//	/**
//	 * 判断是否超级管理员.
//	 */
//	public static boolean isSupervisor(User user) {
//		return ((user.getId() != null) && (user.getId() == SysConstants.ADMIN_ID));
//	}
//	public static boolean isSupervisor(Long userId) {
//		return ((userId != null) && (userId == SysConstants.ADMIN_ID));
//	}
//	
//	/**
//	 * 判断是否超级管理员或辅助管理员
//	 */
//	public boolean isAdmin(Long userId) {
//		if((userId != null) && (userId == 1L)){
//			return true;
//		}
//		
//		User user = getUser(userId);
//		if(user == null) return false;
//		
////		if(SysConstants.ADMIN.equals(user.getRoleNames()) || SysConstants.SUBADMIN.equals(user.getRoleNames())){
////			return true;
////		}
//		
//		return false;
//	}
//
//	/**
//	 * 根据用户id查询用户
//	 * @param id 用户id
//	 * @return
//	 */
//	public User getUser(Long id) {
//		return userDao.findOne(id);
//	}
//    public User getSecUser(Long id) {
//        return userDao.findBySecId(id);
//    }
//
//
//
//	/**
//	 * 获取当前用户数量.
//	 */
//	public Long getUserCount() {
//		return userDao.count();
//	}
//
	/**
	 * 使用二级缓存查询User
	 * @param loginName
	 * @return
	 */
	public User findByLoginName(String loginName) {
//		User user = userDaoPlus.findByLoginName(loginName);
		User user = userDao.findByLoginName(loginName);
//		UserInfo userInfo = userService.getUserDetail(user.getId());
//		user.setUserInfo(userInfo);
		return user;
//		return null;
	}
//	
//	public User findByLoginNameAndOrgId(String loginName, Long orgId) {
//		return userDaoPlus.findByLoginNameAndOrgId(loginName, orgId);
//	}
//	public List<User> findByAliasNameAndOrgId(String aliasName, Long orgId) {
//		return userDaoPlus.findByAliasNameAndOrgId(aliasName, orgId);
//	}
//	
////	public List<UserInfo> queryAllUser(){
////		return userInfoDao.findAllUserInfo(BaseController.getCurrentOrgId());
////	}
//	
//	public Page<User> searchUser(UserVo user) throws Exception{
//		PageInfo pageinfo = user.getPageInfo();
//		if(pageinfo==null){
//			pageinfo = new PageInfo();
//		}
//		user.setRoleList(null);
//		Map<String, Object> searchParams = SearchFilterUtil.convertBean(user);
//		
//
//		Map<String, SearchFilter> filters = SearchFilterUtil.parse(searchParams);
//
//        //过滤admin
//        if(filters.get("userName")!=null){
//            filters.put("userName", new SearchFilter("userName", SearchFilter.Operator.LIKE, filters.get("userName").value));
//        }
//		Specification<User> spec = UserSearchSpecs.bySearchFilter(filters.values());
//		PageRequest pageRequest = buildPageRequest(pageinfo.getPageNumber(), pageinfo.getPageSize(), pageinfo.getSortColumn());		
//		Page<User> page= userDao.findAll(spec,pageRequest);
//
//		return page;
//	}
//	
//	/**
//	 * 查询领导、秘书等普通权限，且未锁定的用户
//	 * 不含翻页
//	 * @return
//	 */
////	public List<Object[]> searchCommonUser() {
////		return userDao.findUsersWithRole(
////				Lists.newArrayList(SysConstants.USER),
////				BaseController.getCurrentOrgId());
////	}
//	
////	public List<Object[]> searchTrueNameUser(String userName) {
////		return userDaoPlus.searchTrueNameUser(
////				Lists.newArrayList(SysConstants.USER),
////				BaseController.getCurrentOrgId(), userName);
////	}
//
//
//	
////	public List<Object[]> searchCommonUserWithUserName(String userName) {
////		return userDaoPlus.findUsersWithRoleAndUserName(
////				Lists.newArrayList(SysConstants.USER), userName,
////				BaseController.getCurrentOrgId());
////	}
//	
//	
////	public List<User> findAllUserWithoutBind(User user) {
////		String roles = user.getRoleNames();
////		List<String> ids = Lists.newArrayList();
////		if(roles.contains(SysConstants.USER)){
////			ids.add(SysConstants.ASSISTANT);
////			ids.add(SysConstants.AGENCY);
////		}else if(roles.contains(SysConstants.ASSISTANT)){
////			ids.add(SysConstants.USER);
////		}
////		if(ids.isEmpty()){
////			return null;
////		}
////		return userDao.findAllUserWithRole(ids,BaseController.getCurrentOrgId());
////	}
//	
//	/**
//	 * 获取所有未绑定领导的秘书
//	 * @return
//	 */
////	public List<User> findAllAssistantWithoutBind() {
////		List<String> ids = Lists.newArrayList(SysConstants.ASSISTANT);
////	
////		return userDao.findAllUserWithRole(ids,BaseController.getCurrentOrgId());
////	}
//	
//	public List<User> findUsersByIds(List<Long> userIds) {
//		return userDao.findUsersByIds(userIds);
//	}
//
//	
//	
//
//
//
//	// --------------------//
//	// Role Management //
//	// --------------------//
//
//	public List<Role> getAllRole() {
//		return roleDao.findCommonRole();
//	}
//	
//	/**
//	 * 切换秘书代理角色
//	 * @param roleName
//	 */
////	@Transactional(readOnly = false)
////	public User swichAgencyRole(String roleName) {
////		User user = getUser(BaseController.getLoginUserId());
////		user.getRoleList().clear();
////		
////		Role role = new Role(this.getRoleIdByName(roleName));
////		user.getRoleList().add(role);
////		
////		userDao.save(user);
////		
////		return user;
////		
////	}
//
//	// -----------------//
//	// Setter methods //
//	// -----------------//
//
//	
//
//
//
//
//
//	
//	/**
//	 * 逻辑 注销／恢复 用户
//	 * @param userId
//	 */
////	@Transactional(readOnly = false)
////    public void lockUser(Long userId,Integer isLock){
////        User user = userDao.findOne(userId);
////
////        if(isLock.intValue() == SysConstants.USER_ACTIVITY_ENABLED){
////            this.checkUserInfo(user);
////        }
////
////        user.setIsLock(isLock);
////        user.getUserInfo().setIsLock(isLock);
////        user.getUserInfo().setUpdateDate(DateUtil.getCurrentDate());
////        userDao.save(user);
////
////        //********************同步node聊天应用---锁定用户****************************
////        Map<String,String> userMap = new HashMap<String,String>();
////        userMap.put("refId", userId.toString());
////        userMap.put("lockFlag", isLock.toString());
////        boolean syncNodeUser = chatConnection.editUser(userMap);
////        if(!syncNodeUser){
////            throw new RestException("sync node data fail");
////        }
////        //********************同步node聊天应用---修改密码****************************
////    }
//	
////	/**
////	 * 返回信息中，过滤用户隐私信息
////	 * @param user
////	 */
////	@Transactional(readOnly = true)
////	public static void privacyFilter(User user) throws Exception{
////		//辅助管理员不能看用户个人信息（但能修改）
////		if(BaseController.hasRole(SysConstants.SUBADMIN)){
////			user.setLoginName(SysConstants.PRIVACY_FILTER);
////			UserInfo ui = user.getUserInfo();
////			if(ui!=null&&ui.getId()!=null){
////				UserInfo uiNew = new UserInfo();
////				uiNew.setId(ui.getId());
////				privacyFilterBean(uiNew);
////				user.setUserInfo(uiNew);
////			}
////		}
////	}
//	
////	@Transactional(readOnly = true)
////	public static void privacyFilter(List<User> userList)  throws Exception{
////		//辅助管理员不能看用户个人信息（但能修改）
////		if(BaseController.hasRole(SysConstants.SUBADMIN)&&userList!=null){
////			for(User user:userList){
////				user.setLoginName(SysConstants.PRIVACY_FILTER);
////				UserInfo ui = user.getUserInfo();
////				if(ui!=null&&ui.getId()!=null){
////					UserInfo uiNew = new UserInfo();
////					uiNew.setId(ui.getId());
////					privacyFilterBean(uiNew);
////					user.setUserInfo(uiNew);
////				}
////			}
////		}
////	}
//	
//	public static void privacyFilterBean(Object target) throws Exception {
//        Class type = target.getClass();  
//        BeanInfo beanInfo = Introspector.getBeanInfo(type);  
//  
//        PropertyDescriptor[] propertyDescriptors =  beanInfo.getPropertyDescriptors();  
//        for (int i = 0; i< propertyDescriptors.length; i++) {  
//            PropertyDescriptor descriptor = propertyDescriptors[i];  
//            String propertyName = descriptor.getName();
//
//            if (!propertyName.equals("class") && descriptor.getPropertyType().equals(String.class)) {
//            	Method writeMethod = descriptor.getWriteMethod();
//                if(writeMethod!=null){
//                	writeMethod.invoke(target,SysConstants.PRIVACY_FILTER);
//                }
//            }  
//        }  
//        
//    }
//	
//	
////	public List<Object[]> searchUserByNameOrMail(String condition) {
////		List<Object[]> userList = userDaoPlus.findUserByNameOrTeamOrMail(Lists
////				.newArrayList(SysConstants.USER,
////						SysConstants.ASSISTANT,
////						SysConstants.AGENCY),
////						condition.toUpperCase(),condition, BaseController.getCurrentOrgId());
////		return userList;
////	}
//	
//	public List<Long> findAllCommonUserId(Long orgId){
//		return userDaoPlus.findAllUserWithRole(Lists.newArrayList(SysConstants.USER), orgId);
//	}
//
////	public User findCompanyAdmin(Long orgId) {
////		List<User> list = userDao.findCompanyAdmin(orgId, Lists.newArrayList(SysConstants.SUBADMIN));
////		if(list != null && list.size() > 0) {
////			return list.get(0);
////		}
////		return null;
////	}
//
//    public Long getRoleIdByName(String name){
//        Role role = roleDao.findByName(name);
//        if(role==null){
//            throwException(BusinessStatus.NOTFIND,"role name is not exist!");
//        }
//        return role.getId();
//    }
//
////    public boolean checkHasRole(Long userId,String roleName){
////        User user = userDao.findOne(userId);
////        Set<Role> roles = user.getRoleList();
////        for(Role role:roles){
////            if(role.getName().equals(roleName)){
////                return true;
////            }
////        }
////        return false;
////    }
//	
}
